import http from './http'

// NOTE: Adjust param names if your backend differs
// Common mapping used here: { pageNum, pageSize, keyword, status }
export function pageUsers(params) {
  return http.get('/intelligent-login/user/page', { params })
}

// Create user
export function createUser(data) {
  return http.post('/intelligent-login/user', data)
}

// Fetch all roles (used for selection)
export function listRoles() {
  return http.get('/intelligent-login/role')
}

// Fetch all departments (used for selection)
// Backend: GET /intelligent-set/dept -> { code, msg, data: [ { departmentId, departmentCode, departmentName, ... } ] }
export function listDepts(params = {}) {
  // Directly returns full list (array in response.data.data)
  return http.get('/intelligent-set/dept', { params })
}

// Search departments with query params (same as listDepts, kept for clarity/semantics)
export function searchDepts(params = {}) {
  return http.get('/intelligent-set/dept', { params })
}

// Page departments (POST body): { pageNum, pageSize, keyword, status }
export function pageDepts(data) {
  return http.post('/intelligent-set/dept/page', data)
}

// Create department
export function createDept(data) {
  return http.post('/intelligent-set/dept', data)
}

// Update department (body must include departmentId)
export function updateDept(data) {
  return http.put('/intelligent-set/dept', data)
}

// Delete department by id (assumes backend accepts id as query param)
export function deleteDept(id) {
  return http.delete('/intelligent-set/dept', { params: { id } })
}

// List all users (for selectors)
export function listUsers(params = {}) {
  return http.get('/intelligent-login/user/list', { params })
}

// Update user (backend expects full body with userId)
export function updateUser(data) {
  // data should contain: userId, username, realName, deptId, roleId, hireDate, remark
  return http.put('/intelligent-login/user', data)
}

// Delete user via query param ?id=
export function deleteUser(id) {
  return http.delete('/intelligent-login/user', { params: { id } })
}

export function toggleUserStatus(userId, status) {
  // backend may expect body or query; adjust if needed
  return http.put(`/intelligent-login/user/${userId}/status`, { status })
}
